package com.xingkeduo.pojo.table;

import com.baomidou.mybatisplus.annotation.TableName;
import com.xingkeduo.pojo.enums.OrderStatus;
import com.xingkeduo.pojo.enums.RefundType;
import com.xingkeduo.utils.TableAnnotations;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author chi  2019-03-26 13:59
 **/
@Slf4j
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@TableName(value = "t_order_refund")
public class OrderRefund extends BaseTable<Order> {

    @TableAnnotations("退款状态")
    private long orderId;



    @TableAnnotations("用户id")
    @Length(max = 10, message = "length长度在[5,17]之间")
    private String userId;

    @TableAnnotations("退款状态")
    private String refundStatus;

    @TableAnnotations("发型师退款原因")
    private String refundReason;

    @TableAnnotations("退款驳回原因")
    private String refundRejectReason;

    @TableAnnotations("退款方式")
    private RefundType refundType;

    @TableAnnotations("第三方退款流水号")
    private String refundTradeNo;

    @TableAnnotations("退款时间")
    private LocalDateTime refundTime;

    @TableAnnotations("退款驳回时间")
    private LocalDateTime refundRejectTime;


    @TableAnnotations("发起退款时间")
    private LocalDateTime sponsorTime;

    @TableAnnotations("用户退款金额")
    private BigDecimal backMoney;

    //发起人
    private String sponsorId;
    private String sponsorName;

    //审核人
    private String auditingId;
    private String auditingName;


    //查询用
    private String orderNo;
    private String storeId;
    private String adminId;
    private LocalDateTime serveStartTime;
    private LocalDateTime serveEndTime;





    public void refund(OrderStatus orderStatus) {
        this.refundStatus = orderStatus.getValue();
        if (OrderStatus.REFUND_DONE.equals(orderStatus)) {
            this.refundTime = LocalDateTime.now();
        }

        if(OrderStatus.REFUND_APPLY.equals(orderStatus)){
            this.auditingId = "";
            this.auditingName = "";
        }
    }

    /**
     * 驳回
     * @param status
     * @param remark
     */
    public void reject(OrderStatus status, String remark) {
        this.refundStatus = status.getValue();
        this.refundRejectReason = remark;
        this.refundRejectTime = LocalDateTime.now();
    }
}
